package control;
import java.util.ArrayList;

import model.*;
import db.*;

public class ProductCtrl
{
	DBProduct dbPro = new DBProduct();
	DBClothing dbClo = new DBClothing();
	DBEquipment dbEqu = new DBEquipment();
	DBGunReplicas dbGun = new DBGunReplicas();
	
	public ProductCtrl()
	{
		
	}
	
	//Product
	public ArrayList<Product> getAllProducts()
	{
		ArrayList<Product> allPro = new ArrayList<Product>();
		allPro = dbPro.getAllProducts(false);
		return allPro;
	}
	
	public Product getProductID(String id)
	{
		return dbPro.getProductID(id, true);
	}
	
	public void insertProduct(int id, String name, double purchasePrice, double salesPrice, double rentPrice, String country, int minStock, int supplierID, String pType) throws Exception
	{
		Product toInsert = new Product();
		toInsert.setId(id);
		toInsert.setName(name);
		toInsert.setPurchasePrice(purchasePrice);
		toInsert.setSalesPrice(salesPrice);
		toInsert.setRentPrice(rentPrice);
		toInsert.setCountry(country);
		toInsert.setMinStock(minStock);
		toInsert.setSupplierID(supplierID);
		toInsert.setpType(pType);
		dbPro.insertProduct(toInsert);
	}
	
	public int updateProduct(int id, String name, double purchasePrice, double salesPrice, double rentPrice, String country, int minStock, int supplierID, String pType)
	{
		Product pro = new Product();
		pro.setId(id);
		pro.setName(name);
		pro.setPurchasePrice(purchasePrice);
		pro.setSalesPrice(salesPrice);
		pro.setRentPrice(rentPrice);
		pro.setCountry(country);
		pro.setMinStock(minStock);
		pro.setSupplierID(supplierID);
		pro.setpType(pType);
		return dbPro.updateProduct(pro);
	}
	
	public void deleteProduct(String id)
	{
		dbPro.deleteProduct(id);
	}
	
	//Clothing
	public ArrayList<Clothing> getAllClothings()
	{
		ArrayList<Clothing> allClo = new ArrayList<Clothing>();
		allClo = dbClo.getAllClothings(false);
		return allClo;
	}
	
	public Clothing getClothingID(String id)
	{
		return dbClo.getClothingID(id, true);
	}
	
	public void insertClothing(int id, String name, double purchasePrice, double salesPrice, double rentPrice, String country, int minStock, int supplierID, String pType, String size, String color) throws Exception
	{
		Clothing toInsert = new Clothing();
		insertProduct(id, name, purchasePrice, salesPrice, rentPrice, country, minStock, supplierID, pType);
		toInsert.setSize(size);
		toInsert.setColor(color);
		toInsert.setId(id);
		dbClo.insertClothing(toInsert);
	}
	
	public int updateClothing(int id, String name, double purchasePrice, double salesPrice, double rentPrice, String country, int minStock, int supplierID, String pType, String size, String color)
	{
		Clothing clo = new Clothing();
		updateProduct(id, name, purchasePrice, salesPrice, rentPrice, country, minStock, supplierID, pType);
		clo.setSize(size);
		clo.setColor(color);
		clo.setId(id);
		return dbClo.updateClothing(clo);
	}
	
	public void deleteClothing(String id)
	{
		dbClo.deleteClothing(id);
	}
	
	//Equipment
	public ArrayList<Equipment> getAllEquipments()
	{
		ArrayList<Equipment> allEqu = new ArrayList<Equipment>();
		allEqu = dbEqu.getAllEquipments(false);
		return allEqu;
	}
	
	public Equipment getEquipmentID(String id)
	{
		return dbEqu.getEquipmentID(id, true);
	}
	
	public void insertEquipment(int id, String name, double purchasePrice, double salesPrice, double rentPrice, String country, int minStock, int supplierID, String pType, String type, String description) throws Exception
	{
		Equipment toInsert = new Equipment();
		insertProduct(id, name, purchasePrice, salesPrice, rentPrice, country, minStock, supplierID, pType);
		toInsert.setType(type);
		toInsert.setDescription(description);
		toInsert.setId(id);
		dbEqu.insertEquipment(toInsert);
	}
	
	public int updateEquipment(int id, String name, double purchasePrice, double salesPrice, double rentPrice, String country, int minStock, int supplierID, String pType, String type, String description)
	{
		Equipment equ = new Equipment();
		updateProduct(id, name, purchasePrice, salesPrice, rentPrice, country, minStock, supplierID, pType);
		equ.setType(type);
		equ.setDescription(description);
		equ.setId(id);
		return dbEqu.updateEquipment(equ);
	}
	
	public void deleteEquipment(String id)
	{
		dbEqu.deleteEquipment(id);
	}
	
	//Gunreplicas
	public ArrayList<GunReplicas> getAllGunReplicass()
	{
		ArrayList<GunReplicas> allGun = new ArrayList<GunReplicas>();
		allGun = dbGun.getAllGunReplicass(false);
		return allGun;
	}
	
	public GunReplicas getGunReplicasID(String id)
	{
		return dbGun.getGunReplicasID(id, true);
	}
	
	public void insertGunReplicas(int id, String name, double purchasePrice, double salesPrice, double rentPrice, String country, int minStock, int supplierID, String pType, String fabric, String caliber) throws Exception
	{
		GunReplicas toInsert = new GunReplicas();
		insertProduct(id, name, purchasePrice, salesPrice, rentPrice, country, minStock, supplierID, pType);
		toInsert.setFabric(fabric);
		toInsert.setCaliber(caliber);
		toInsert.setId(id);
		dbGun.insertGunReplicas(toInsert);
	}
	
	public int updateGunReplicas(int id, String name, double purchasePrice, double salesPrice, double rentPrice, String country, int minStock, int supplierID, String pType, String fabric, String caliber)
	{
		GunReplicas gun = new GunReplicas();
		updateProduct(id, name, purchasePrice, salesPrice, rentPrice, country, minStock, supplierID, pType);
		gun.setFabric(fabric);
		gun.setCaliber(caliber);
		gun.setId(id);
		return dbGun.updateGunReplicas(gun);
	}
	
	public void deleteGunReplicas(String id)
	{
		dbGun.deleteGunReplicas(id);
	}
}
